Wala'a Nezar | Welcome

welcome world

Input Devices

For this week assignment, we had to add an input device to our boards and read the result, but since we are in full quarantine here in Irbid, and I don’t have any hardware available, I had to simulate my circuit using tinkercad website for now, and when we get back to the lab; hopefully soon, I can get back to this week’s assignment and edit it.

Tinkercad is an easy-to-use and very fun circuit building online tool, which help beginners in visual learning. Our instructor Nadine send to us a tutorial video with instruction of what we have to do this week and how to do that, so I started making my first circuit which was very simple and fun.


I started tinkering with RGB LED and switch to control the LEDs and I added a photoresistor to control the brightnss of the LED depending on it's reading.

The components I used in the circuit are listed in the figure below, which is a screenshot from the website also.



When I connected all the parts together in the breadboard, I started writing the code. Since I used Arduino before, this process was easy. You can see and see the code below.


        #include "pins_arduino.h" // Arduino pre-1.0 needs this


uint8_t readCapacitivePin(int pinToMeasure) {

  

  volatile uint8_t* port;

  volatile uint8_t* ddr;

  volatile uint8_t* pin;
   byte bitmask;

  port = portOutputRegister(digitalPinToPort(pinToMeasure));

  ddr = portModeRegister(digitalPinToPort(pinToMeasure));

  bitmask = digitalPinToBitMask(pinToMeasure);

  pin = portInputRegister(digitalPinToPort(pinToMeasure));

  // Discharge the pin first by setting it low and output

  *port &= ~(bitmask);

  *ddr  |= bitmask;

  delay(1);

  uint8_t SREG_old = SREG; //back up the AVR Status Register

  // Prevent the timer IRQ from disturbing our measurement

  noInterrupts();

  // Make the pin an input with the internal pull-up on

  *ddr &= ~(bitmask);

  *port |= bitmask;



  // Now see how long the pin to get pulled up. This manual unrolling of the loop

  // decreases the number of hardware cycles between each read of the pin,

  // thus increasing sensitivity.

  uint8_t cycles = 17;

  if (*pin & bitmask) { cycles =  0;}

  else if (*pin & bitmask) { cycles =  1;}

  else if (*pin & bitmask) { cycles =  2;}

  else if (*pin & bitmask) { cycles =  3;}

  else if (*pin & bitmask) { cycles =  4;}

  else if (*pin & bitmask) { cycles =  5;}

  else if (*pin & bitmask) { cycles =  6;}

  else if (*pin & bitmask) { cycles =  7;}

  else if (*pin & bitmask) { cycles =  8;}

  else if (*pin & bitmask) { cycles =  9;}

  else if (*pin & bitmask) { cycles = 10;}

  else if (*pin & bitmask) { cycles = 11;}

  else if (*pin & bitmask) { cycles = 12;}

  else if (*pin & bitmask) { cycles = 13;}

  else if (*pin & bitmask) { cycles = 14;}

  else if (*pin & bitmask) { cycles = 15;}

  else if (*pin & bitmask) { cycles = 16;}



  // End of timing-critical section; turn interrupts back on if they were on before, or leave them off if they were off before

  SREG = SREG_old;



  // Discharge the pin again by setting it low and output

  //  It's important to leave the pins low if you want to 

  //  be able to touch more than 1 sensor at a time - if

  //  the sensor is left pulled high, when you touch

  //  two sensors, your body will transfer the charge between

  //  sensors.

  *port &= ~(bitmask);

  *ddr  |= bitmask;



  return cycles;
  
  #define sensorPin PA7;
   int dc1 = PA3 ;
   int dc1 = PA2 ;
   
void setup() {
  // put your setup code here, to run once:
  pinMode(dc1, OUTPUT);  
  pinMode(dc1, OUTPUT); 
  pinMode(sensorPin, INPUT);
}

void loop() {
  // put your main code here, to run repeatedly:

int sensorPin = readCapacitivePin( pinNumber);
if (sensorPin > 5 ) {
  digitalWrite (dc1,HIGH);
  digitalWrite (dc2,LOW);
}
else
{digitalWrite (dc2,HIGH);
  digitalWrite (dc1,LOW);
  }
}
 
        

After writing the correct code, all what I did is starting the simulation to test all the connections and the code.


after the kit arrived to my house, I started applying all what I did with tinkercad, below you can see the circuit I made.


and the video below shoes the test.









code S

Touch Sensor

So as we now got back to the lab, I had the chance to design a new board for both input and outout devices weekly assignments, the idea was a touch button that allows you to reverse the direction of a DC motor each time you touch it.

the touch sensor concept is very easy, you just have to add a pad to the schematic and then connect it to one of the attiny44 pins. In the programming stage we will use function allow us to use that pin as an analog input pin.

I started as always with the eagle schematics, added all the components I need , they all listed in the image below, and then started adding connections between them . honestly I started finding this step very easy ^-^ .

I used for this board an Attiny44 microcontroller, and I used a H-Bridge to drive the motor in two directions, and also I used one decoupling capacitor to be physically close to the VCC pin from the microcontroller.

For the power supply I added two pin headers, and other two pin headers for the motor.
Also, you can see in the board an ISP to be able to upload the codes to the board, and I added FTDI pin headers for the future if I needed it ( I actually needed that to add the Limit switch as I described in the machine design week). The last thing I used was the Bluetooth module, I also added it just in case I needed it in whatever project I used this board in.






And then directly started the routing process, it’s as always fun but tricky. So, after editing the clearances and sizes of the mill bet started adding the routs. Its depends on the initial positioning of the components. I didn’t care about the place of The pad for the touch pin, since im palnning to connect it to a wire to increase the touching area

<<<<<<< HEAD

Then I exported the images as monochrome with 1500 resolution, and imported them to the fab modules.







=======

Then I exported the images as monochrome with 1500 resolution, and imported them to the fab modules.

In the fab Modules, I imported the traces png image as input and the 1/64 traces milling method for the traces milling and 1/32 for the outline cut. And from the right side panel, I selected the machine to be SRM-20 as our machine in the lab and the speed to be 1.

Since the stock thickness is 1.7mm, I selected the cut for the traces to be .6mm on one pass, and 1.7 mm on 3 passes ( .6 for each pass) for the outline.







>>>>>>> 94f5539a02368d46924abaeec9ba58b88891ec14

Then the soldering stage, nothing where challenging at all, I kind of used to all of these steps.


After the board was finish, the breath taking moment came; each time I start testing the board I feel terrifled. but fortunately, it worked from the very first time. I made burn bootloader and it worked very good, and then uploaded a blinking code to it to make sure that everything is going well.








After connecting the DC motor as I explained in the output devices page, was the time to test the whole system.

So, I wrote a program to use the touch sensor to change the direction of the motor as seen below.

        #include "pins_arduino.h" // Arduino pre-1.0 needs this


uint8_t readCapacitivePin(int pinToMeasure) {

  

  volatile uint8_t* port;

  volatile uint8_t* ddr;

  volatile uint8_t* pin;
   byte bitmask;

  port = portOutputRegister(digitalPinToPort(pinToMeasure));

  ddr = portModeRegister(digitalPinToPort(pinToMeasure));

  bitmask = digitalPinToBitMask(pinToMeasure);

  pin = portInputRegister(digitalPinToPort(pinToMeasure));

  // Discharge the pin first by setting it low and output

  *port &= ~(bitmask);

  *ddr  |= bitmask;

  delay(1);

  uint8_t SREG_old = SREG; //back up the AVR Status Register

  // Prevent the timer IRQ from disturbing our measurement

  noInterrupts();

  // Make the pin an input with the internal pull-up on

  *ddr &= ~(bitmask);

  *port |= bitmask;



  // Now see how long the pin to get pulled up. This manual unrolling of the loop

  // decreases the number of hardware cycles between each read of the pin,

  // thus increasing sensitivity.

  uint8_t cycles = 17;

  if (*pin & bitmask) { cycles =  0;}

  else if (*pin & bitmask) { cycles =  1;}

  else if (*pin & bitmask) { cycles =  2;}

  else if (*pin & bitmask) { cycles =  3;}

  else if (*pin & bitmask) { cycles =  4;}

  else if (*pin & bitmask) { cycles =  5;}

  else if (*pin & bitmask) { cycles =  6;}

  else if (*pin & bitmask) { cycles =  7;}

  else if (*pin & bitmask) { cycles =  8;}

  else if (*pin & bitmask) { cycles =  9;}

  else if (*pin & bitmask) { cycles = 10;}

  else if (*pin & bitmask) { cycles = 11;}

  else if (*pin & bitmask) { cycles = 12;}

  else if (*pin & bitmask) { cycles = 13;}

  else if (*pin & bitmask) { cycles = 14;}

  else if (*pin & bitmask) { cycles = 15;}

  else if (*pin & bitmask) { cycles = 16;}



  // End of timing-critical section; turn interrupts back on if they were on before, or leave them off if they were off before

  SREG = SREG_old;



  // Discharge the pin again by setting it low and output

  //  It's important to leave the pins low if you want to 

  //  be able to touch more than 1 sensor at a time - if

  //  the sensor is left pulled high, when you touch

  //  two sensors, your body will transfer the charge between

  //  sensors.

  *port &= ~(bitmask);

  *ddr  |= bitmask;



  return cycles;
  
  #define sensorPin PA7;
   int dc1 = PA3 ;
   int dc1 = PA2 ;
   
void setup() {
  // put your setup code here, to run once:
  pinMode(dc1, OUTPUT);  
  pinMode(dc1, OUTPUT); 
  pinMode(sensorPin, INPUT);
}

void loop() {
  // put your main code here, to run repeatedly:

int sensorPin = readCapacitivePin( pinNumber);
if (sensorPin > 5 ) {
  digitalWrite (dc1,HIGH);
  digitalWrite (dc2,LOW);
}
else
{digitalWrite (dc2,HIGH);
  digitalWrite (dc1,LOW);
  }
}
 
        
        
































And it worked amazingly, see the video below.











download the boad and schematic from HERE BOARD , SCHEMATIC.